package com.my.blogs.personblog.mapper;

import com.my.blogs.personblog.enity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from personalblog.visituser where username=#{username} and password=#{password}")
    public Boolean existsByUsername(String username);
    @Select("select personalblog.visituser.username,personalblog.visituser.password from visituser where username=#{username} and password=#{password} ")
    public User login(String username, String password);
    @Insert("insert into personalblog.visituser (username, password, email, phone, IdCard) values (#{username}, #{password}, #{email}, #{phone}, #{IdCard})")
    public User register(String username, String password, String email, String phone,String IdCard);
    @Select("select * from personalblog.visituser")
    public List<User> selectAllUsers();
    @Select("select * from personalblog.visituser where id=#{id}")
    public User selectUserById(int id);
    @Select("select * from personalblog.visituser where username=#{username}")
    public User selectUserByUsername(String username);
    @Select("select * from personalblog.visituser where email=#{email}")
    public User selectUserByEmail(String email);
    @Select("select * from personalblog.visituser where phone=#{phone}")
    public User selectUserByPhone(String phone);
    @Insert("insert into personalblog.visituser (username, password, email, phone, IdCard) values (#{username}, #{password}, #{email}, #{phone}, #{IdCard}")
    public Boolean insertUser(User user);
    @Update("update personalblog.visituser set username=#{username}, password=#{password}, email=#{email}, phone=#{phone}, IdCard=#{IdCard} where id=#{id}")
    public Boolean updateUser(User user);
    @Delete("delete from personalblog.visituser where id=#{id}")
    public Boolean deleteUser(int id);
    @Select("select * from personalblog.visituser order by id=#{id}")
    public List<User> sortById(int id);
    @Select("select * from personalblog.visituser limit #{page},#{pageSize}")
    public List<User> selectPage(int page, int pageSize);
}
